package com.ttsx.controller;

import com.ttsx.pojo.dto.cart.CartUpdateNumDTO;
import com.ttsx.pojo.entity.Cart;
import com.ttsx.service.CartService;
import com.ttsx.core.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wb
 * @since 2025-03-02
 */

@RestController
@RequestMapping("cart")
public class CartController {

    @Autowired
    private CartService cartService;


    @PostMapping("save")
    public Result<?> save(@RequestBody Cart cart){
        return Result.success(cartService.saveCart(cart));
    }

    @GetMapping("getByUserId")
    public Result<?> getByUserId(HttpServletRequest request){
        return Result.success(cartService.getByUserId(request));
    }

    @PutMapping("update/num")
    public Result<?> updateNum(@RequestBody CartUpdateNumDTO cartUpdateNumDTO){
        return cartService.updateNum(cartUpdateNumDTO) ? Result.success() : Result.failure();
    }
}
